package com.loc;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.text.TextUtils;
import com.gisocn.onemap.tdt.TDTConstant;
import com.loc.m;
import com.sangfor.ssl.service.utils.IGeneral;
import com.tencent.smtt.sdk.TbsListener;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONObject;

/* compiled from: AuthUtil.java */
/* loaded from: classes2.dex */
public final class fs {
    private static volatile boolean i = false;
    private static boolean j = true;
    private static int k = 1000;
    private static int l = 200;
    private static boolean m = false;
    private static int n = 20;
    private static int o = 0;
    private static volatile int p = 0;
    private static boolean q = true;
    private static boolean r = false;
    private static int s = -1;
    private static long t;
    private static ArrayList<String> u = new ArrayList<>();
    private static ArrayList<String> v = new ArrayList<>();
    private static volatile boolean w = false;
    private static boolean x = true;
    private static long y = 300000;
    private static boolean z = false;
    private static double A = 0.618d;
    private static boolean B = true;
    private static int C = 80;
    private static int D = 5;
    static long a = 3600000;
    private static boolean E = false;
    private static boolean F = true;
    private static boolean G = false;
    public static volatile long b = 0;
    static boolean c = false;
    private static boolean H = true;
    private static long I = -1;
    private static boolean J = true;
    private static int K = 1;
    private static boolean L = false;
    private static int M = 5;
    private static boolean N = false;
    private static String O = "CMjAzLjEwNy4xLjEvMTU0MDgxL2Q";
    private static long P = 0;
    public static boolean d = false;
    public static boolean e = false;
    public static int f = 20480;
    public static int g = 10800000;
    public static boolean h = false;

    public static void a(final Context context) {
        if (i) {
            return;
        }
        i = true;
        m.a(context, ft.c(), ft.d(), new m.a() { // from class: com.loc.fs.1
            @Override // com.loc.m.a
            public final void a(m.b bVar) {
                fs.a(context, bVar);
            }
        });
    }

    private static void a(Context context, JSONObject jSONObject, SharedPreferences.Editor editor) {
        try {
            JSONObject optJSONObject = jSONObject.optJSONObject("13S");
            if (optJSONObject != null) {
                long optInt = optJSONObject.optInt("at", 123) * 60 * 1000;
                a = optInt;
                ga.a(editor, "13S_at", optInt);
                e(optJSONObject, editor);
                try {
                    boolean a2 = m.a(optJSONObject.optString("nla"), true);
                    F = a2;
                    ga.a(editor, "13S_nla", a2);
                } catch (Throwable unused) {
                }
                try {
                    boolean a3 = m.a(optJSONObject.optString("asw"), true);
                    H = a3;
                    ga.a(editor, "asw", a3);
                } catch (Throwable unused2) {
                }
                try {
                    JSONArray optJSONArray = optJSONObject.optJSONArray("mlpl");
                    if (optJSONArray == null || optJSONArray.length() <= 0 || context == null) {
                        G = false;
                        ga.a(editor, "13S_mlpl");
                        return;
                    }
                    ga.a(editor, "13S_mlpl", x.b(optJSONArray.toString()));
                    G = a(context, optJSONArray);
                } catch (Throwable unused3) {
                }
            }
        } catch (Throwable th) {
            ft.a(th, "AuthUtil", "loadConfigAbleStatus");
        }
    }

    private static void a(m.b bVar, SharedPreferences.Editor editor) {
        try {
            m.b.a aVar = bVar.g;
            if (aVar != null) {
                boolean z2 = aVar.a;
                j = z2;
                ga.a(editor, "exception", z2);
                JSONObject jSONObject = aVar.c;
                if (jSONObject != null) {
                    k = jSONObject.optInt("fn", k);
                    int optInt = jSONObject.optInt("mpn", l);
                    l = optInt;
                    if (optInt > 500) {
                        l = TbsListener.ErrorCode.INFO_CODE_MINIQB;
                    }
                    if (l < 30) {
                        l = 30;
                    }
                    m = m.a(jSONObject.optString("igu"), false);
                    n = jSONObject.optInt("ms", n);
                    p = jSONObject.optInt("rot", 0);
                    o = jSONObject.optInt("pms", 0);
                }
                by.a(k, m, n, o);
                ca.a(m, o);
                ga.a(editor, "fn", k);
                ga.a(editor, "mpn", l);
                ga.a(editor, "igu", m);
                ga.a(editor, "ms", n);
                ga.a(editor, "rot", p);
                ga.a(editor, "pms", o);
            }
        } catch (Throwable th) {
            ft.a(th, "AuthUtil", "loadConfigDataUploadException");
        }
    }

    private static void a(JSONObject jSONObject, SharedPreferences.Editor editor) {
        try {
            JSONObject optJSONObject = jSONObject.optJSONObject("11G");
            if (optJSONObject != null) {
                boolean a2 = m.a(optJSONObject.optString("able"), true);
                x = a2;
                if (a2) {
                    y = optJSONObject.optInt(TDTConstant.TILE_MATRIX_SET_2000, TbsListener.ErrorCode.ERROR_CODE_LOAD_BASE) * 1000;
                }
                z = m.a(optJSONObject.optString("fa"), false);
                A = Math.min(1.0d, Math.max(0.2d, optJSONObject.optDouble("ms", 0.618d)));
                ga.a(editor, "ca", x);
                ga.a(editor, "ct", y);
                ga.a(editor, "11G_fa", z);
                ga.a(editor, "11G_ms", String.valueOf(A));
            }
        } catch (Throwable th) {
            ft.a(th, "AuthUtil", "loadConfigDataCacheAble");
        }
    }

    public static boolean a() {
        return j;
    }

    public static boolean a(long j2) {
        if (x) {
            long a2 = gb.a() - j2;
            long j3 = y;
            return j3 < 0 || a2 < j3;
        }
        return false;
    }

    static boolean a(Context context, m.b bVar) {
        SharedPreferences.Editor editor;
        try {
            editor = ga.a(context, "pref");
            try {
                a(bVar, editor);
                c(context);
                JSONObject jSONObject = bVar.f;
                if (jSONObject == null) {
                    if (editor != null) {
                        try {
                            ga.a(editor);
                        } catch (Throwable unused) {
                        }
                    }
                    return true;
                }
                a(context, jSONObject, editor);
                a(jSONObject, editor);
                d(jSONObject, editor);
                f(jSONObject, editor);
                h(jSONObject, editor);
                g(jSONObject, editor);
                i(jSONObject, editor);
                b(jSONObject, editor);
                c(jSONObject, editor);
                if (editor != null) {
                    try {
                        ga.a(editor);
                    } catch (Throwable unused2) {
                    }
                }
                return true;
            } catch (Throwable unused3) {
                if (editor != null) {
                    try {
                        ga.a(editor);
                        return false;
                    } catch (Throwable unused4) {
                        return false;
                    }
                }
                return false;
            }
        } catch (Throwable unused5) {
            editor = null;
        }
    }

    private static boolean a(Context context, JSONArray jSONArray) {
        if (jSONArray != null) {
            try {
                if (jSONArray.length() > 0 && context != null) {
                    for (int i2 = 0; i2 < jSONArray.length(); i2++) {
                        if (gb.b(context, jSONArray.getString(i2))) {
                            return true;
                        }
                    }
                }
            } catch (Throwable unused) {
            }
        }
        return false;
    }

    public static int b() {
        return l;
    }

    public static void b(Context context) {
        if (w) {
            return;
        }
        w = true;
        try {
            j = ga.a(context, "pref", "exception", j);
            c(context);
        } catch (Throwable th) {
            ft.a(th, "AuthUtil", "loadLastAbleState p1");
        }
        try {
            k = ga.a(context, "pref", "fn", k);
            l = ga.a(context, "pref", "mpn", l);
            m = ga.a(context, "pref", "igu", m);
            n = ga.a(context, "pref", "ms", n);
            p = ga.a(context, "pref", "rot", 0);
            int a2 = ga.a(context, "pref", "pms", 0);
            o = a2;
            by.a(k, m, n, a2);
            ca.a(m, o);
        } catch (Throwable th2) {
            ft.a(th2, "AuthUtil", "loadLastAbleState p2");
        }
        try {
            x = ga.a(context, "pref", "ca", x);
            y = ga.a(context, "pref", "ct", y);
            z = ga.a(context, "pref", "11G_fa", z);
            double doubleValue = Double.valueOf(ga.a(context, "pref", "11G_ms", String.valueOf(A))).doubleValue();
            A = doubleValue;
            A = Math.max(0.2d, doubleValue);
        } catch (Throwable th3) {
            ft.a(th3, "AuthUtil", "loadLastAbleState p3");
        }
        try {
            c = ga.a(context, "pref", "fr", c);
        } catch (Throwable th4) {
            ft.a(th4, "AuthUtil", "loadLastAbleState p4");
        }
        try {
            H = ga.a(context, "pref", "asw", H);
        } catch (Throwable th5) {
            ft.a(th5, "AuthUtil", "loadLastAbleState p5");
        }
        try {
            I = ga.a(context, "pref", "awsi", I);
        } catch (Throwable th6) {
            ft.a(th6, "AuthUtil", "loadLastAbleState p6");
        }
        try {
            J = ga.a(context, "pref", "15ua", J);
            K = ga.a(context, "pref", "15un", K);
            P = ga.a(context, "pref", "15ust", P);
        } catch (Throwable th7) {
            ft.a(th7, "AuthUtil", "loadLastAbleState p7");
        }
        try {
            L = ga.a(context, "pref", "ok9", L);
            M = ga.a(context, "pref", "ok10", M);
            O = ga.a(context, "pref", "ok11", O);
        } catch (Throwable th8) {
            ft.a(th8, "AuthUtil", "loadLastAbleState p8");
        }
        try {
            d = ga.a(context, "pref", "17ya", false);
            e = ga.a(context, "pref", "17ym", false);
            g = ga.a(context, "pref", "17yi", 2) * 60 * 60 * 1000;
            f = ga.a(context, "pref", "17yx", 100) * 1024;
        } catch (Throwable th9) {
            ft.a(th9, "AuthUtil", "loadLastAbleState p9");
        }
        try {
            b = gb.b();
            a = ga.a(context, "pref", "13S_at", a);
            F = ga.a(context, "pref", "13S_nla", F);
            B = ga.a(context, "pref", "13J_able", B);
            C = ga.a(context, "pref", "13J_c", C);
            D = ga.a(context, "pref", "13J_t", D);
        } catch (Throwable th10) {
            ft.a(th10, "AuthUtil", "loadLastAbleState p10");
        }
        m.b(context);
        try {
            String a3 = ga.a(context, "pref", "13S_mlpl", (String) null);
            if (!TextUtils.isEmpty(a3)) {
                G = a(context, new JSONArray(x.c(a3)));
            }
        } catch (Throwable th11) {
            ft.a(th11, "AuthUtil", "loadLastAbleState p11");
        }
        try {
            boolean a4 = ga.a(context, "pref", "197a", false);
            String a5 = ga.a(context, "pref", "197dv", "");
            String a6 = ga.a(context, "pref", "197tv", "");
            if (a4 && ft.a.equals(a5)) {
                for (String str : ft.b) {
                    if (str.equals(a6)) {
                        ft.a = a6;
                    }
                }
            }
        } catch (Throwable th12) {
            ft.a(th12, "AuthUtil", "loadLastAbleState p12");
        }
        try {
            h = ga.a(context, "pref", "1A6", h);
        } catch (Throwable th13) {
            ft.a(th13, "AuthUtil", "loadSdkEnableConfig p13");
        }
    }

    private static void b(JSONObject jSONObject, SharedPreferences.Editor editor) {
        if (jSONObject == null) {
            return;
        }
        try {
            JSONObject jSONObject2 = jSONObject.getJSONObject("197");
            if (jSONObject2 != null) {
                boolean a2 = m.a(jSONObject2.optString("able"), false);
                ga.a(editor, "197a", a2);
                if (a2) {
                    ga.a(editor, "197dv", jSONObject2.optString("sv", ""));
                    ga.a(editor, "197tv", jSONObject2.optString("tv", ""));
                    return;
                }
                ga.a(editor, "197dv", "");
                ga.a(editor, "197tv", "");
            }
        } catch (Throwable unused) {
        }
    }

    public static int c() {
        if (p < 0) {
            p = 0;
        }
        return p;
    }

    public static void c(Context context) {
        try {
            w c2 = ft.c();
            c2.a(j);
            av.a(context, c2);
        } catch (Throwable unused) {
        }
    }

    private static void c(JSONObject jSONObject, SharedPreferences.Editor editor) {
        if (jSONObject == null) {
            return;
        }
        try {
            JSONObject jSONObject2 = jSONObject.getJSONObject("1A6");
            if (jSONObject2 != null) {
                boolean a2 = m.a(jSONObject2.optString("ic"), false);
                ga.a(editor, "1A6", a2);
                h = a2;
            }
        } catch (Throwable unused) {
        }
    }

    public static long d() {
        return y;
    }

    private static void d(JSONObject jSONObject, SharedPreferences.Editor editor) {
        try {
            JSONObject optJSONObject = jSONObject.optJSONObject("13J");
            if (optJSONObject != null) {
                boolean a2 = m.a(optJSONObject.optString("able"), true);
                B = a2;
                if (a2) {
                    C = optJSONObject.optInt(TDTConstant.TILE_MATRIX_SET_2000, C);
                    D = optJSONObject.optInt("t", D);
                }
                ga.a(editor, "13J_able", B);
                ga.a(editor, "13J_c", C);
                ga.a(editor, "13J_t", D);
            }
        } catch (Throwable th) {
            ft.a(th, "AuthUtil", "loadConfigDataGpsGeoAble");
        }
    }

    private static void e(JSONObject jSONObject, SharedPreferences.Editor editor) {
        if (jSONObject == null) {
            return;
        }
        try {
            boolean a2 = m.a(jSONObject.optString("re"), false);
            c = a2;
            ga.a(editor, "fr", a2);
        } catch (Throwable th) {
            ft.a(th, "AuthUtil", "checkReLocationAble");
        }
    }

    public static boolean e() {
        return x;
    }

    private static void f(JSONObject jSONObject, SharedPreferences.Editor editor) {
        JSONArray optJSONArray;
        try {
            JSONObject optJSONObject = jSONObject.optJSONObject("15O");
            if (optJSONObject != null) {
                if (m.a(optJSONObject.optString("able"), false) && ((optJSONArray = optJSONObject.optJSONArray("fl")) == null || optJSONArray.length() <= 0 || optJSONArray.toString().contains(Build.MANUFACTURER))) {
                    I = optJSONObject.optInt("iv", 30) * 1000;
                } else {
                    I = -1L;
                }
                ga.a(editor, "awsi", I);
            }
        } catch (Throwable unused) {
        }
    }

    public static boolean f() {
        return z;
    }

    public static double g() {
        return A;
    }

    private static void g(JSONObject jSONObject, SharedPreferences.Editor editor) {
        if (jSONObject == null) {
            return;
        }
        try {
            JSONObject jSONObject2 = jSONObject.getJSONObject("17Y");
            if (jSONObject2 != null) {
                boolean a2 = m.a(jSONObject2.optString("able"), false);
                d = a2;
                ga.a(editor, "17ya", a2);
                boolean a3 = m.a(jSONObject2.optString("mup"), false);
                e = a3;
                ga.a(editor, "17ym", a3);
                int optInt = jSONObject2.optInt("max", 20);
                if (optInt > 0) {
                    ga.a(editor, "17yx", optInt);
                    f = optInt * 1024;
                }
                int optInt2 = jSONObject2.optInt("inv", 3);
                if (optInt2 > 0) {
                    ga.a(editor, "17yi", optInt2);
                    g = optInt2 * 60 * 60 * 1000;
                }
            }
        } catch (Throwable unused) {
        }
    }

    private static void h(JSONObject jSONObject, SharedPreferences.Editor editor) {
        try {
            JSONObject optJSONObject = jSONObject.optJSONObject("15U");
            if (optJSONObject != null) {
                boolean a2 = m.a(optJSONObject.optString("able"), true);
                int optInt = optJSONObject.optInt("yn", K);
                P = optJSONObject.optLong("sysTime", P);
                ga.a(editor, "15ua", a2);
                ga.a(editor, "15un", optInt);
                ga.a(editor, "15ust", P);
            }
        } catch (Throwable unused) {
        }
    }

    public static boolean h() {
        return B;
    }

    public static int i() {
        return C;
    }

    private static void i(JSONObject jSONObject, SharedPreferences.Editor editor) {
        int parseInt;
        if (jSONObject == null) {
            return;
        }
        try {
            JSONObject optJSONObject = jSONObject.optJSONObject("17J");
            if (optJSONObject != null) {
                boolean a2 = m.a(optJSONObject.optString("able"), false);
                L = a2;
                ga.a(editor, "ok9", a2);
                if (a2) {
                    String optString = optJSONObject.optString(IGeneral.LOG_TAG_AUTH);
                    String optString2 = optJSONObject.optString("ht");
                    O = optString2;
                    ga.a(editor, "ok11", optString2);
                    m.a(optString, false);
                    N = m.a(optJSONObject.optString("nr"), false);
                    String optString3 = optJSONObject.optString("tm");
                    if (TextUtils.isEmpty(optString3) || (parseInt = Integer.parseInt(optString3)) <= 0 || parseInt >= 20) {
                        return;
                    }
                    M = parseInt;
                    ga.a(editor, "ok10", parseInt);
                }
            }
        } catch (Throwable unused) {
        }
    }

    public static int j() {
        return D;
    }

    public static boolean k() {
        return F;
    }

    public static boolean l() {
        return G;
    }

    public static boolean m() {
        return c;
    }

    public static boolean n() {
        return H;
    }

    public static long o() {
        return I;
    }

    public static boolean p() {
        return N;
    }

    public static boolean q() {
        return L;
    }

    public static String r() {
        return x.c(O);
    }

    public static boolean s() {
        return J && K > 0;
    }

    public static int t() {
        return K;
    }

    public static long u() {
        return P;
    }
}
